// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MATRIX_HH
#define MATRIX_HH

#include <cstdlib>
#include <string>

#define ROWMAJOR 0
#define COLMAJOR 1
#define BIGENDIAN 0
#define LTLENDIAN 1

#define newMatrix(type, nb_col, nb_row, order) \
_newMatrix(nb_col, nb_row, sizeof(type), order)

#pragma pack(push,1)
struct mat_t {
  unsigned int nb_col;
  unsigned int nb_row;
  size_t elt_size;
  char order;
  char endianness;
};

typedef struct {
  struct mat_t desc;
  size_t offset;
  char* data;
} matrix_t;

void load_matrix(const char* filename, matrix_t& matrix);
void save_matrix(const char* filename, const matrix_t& matrix);
matrix_t* _newMatrix(const unsigned int& nb_col,
                     const unsigned int& nb_row,
                     const char& elt_size,
                     const char& order);


// Send/receive files using http with cURL
#ifdef USE_CURL
void get_matrix(const std::string& url, matrix_t& matrix);
void put_matrix(const std::string& url, const std::string& name,
                matrix_t& matrix);
#endif

#endif
